﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace SIS.Utilities
{
    public class General
    {
        public static void LoadDayDropdownList(DropDownList ddlDayList)
        {
            for (int i = 1; i <= 31; i++)
            {
                ddlDayList.Items.Add(new ListItem(i.ToString("00"), i.ToString("00")));

            }
        }

        /// <summary>
        /// format
        /// 1 = two digit
        /// 2 = three first characters
        /// 3 = full month name
        /// </summary>
        /// <param name="ddlMonthList"></param>
        /// <param name="format"></param>
        public static void LoadMonthDropdownList(DropDownList ddlMonthList, int format)
        {
            System.Globalization.DateTimeFormatInfo _mInfo = new System.Globalization.DateTimeFormatInfo();
            //string _mName = _mInfo.GetMonthName(1);
            for (int i = 1; i <= 12; i++)
            {
                if (format == 1)
                {
                    ddlMonthList.Items.Add(new ListItem(i.ToString("00"), i.ToString("00")));
                }
                else if (format == 2)
                {
                    ddlMonthList.Items.Add(new ListItem(_mInfo.GetMonthName(i).Substring(0, 3), i.ToString("00")));
                }
                else if (format == 3)
                {
                    ddlMonthList.Items.Add(new ListItem(_mInfo.GetMonthName(i), i.ToString("00")));
                }
            }
        }
        /// <summary>
        /// format
        /// 1 = full year
        /// 2 = last 2 digit
        /// </summary>
        /// <param name="ddlYearList"></param>
        /// <param name="fromYear"></param>
        /// <param name="toYear"></param>
        /// <param name="format"></param>
        public static void LoadYearDropdownList(DropDownList ddlYearList, int fromYear, int toYear, int format)
        {
            for (int i = fromYear; i <= toYear; i++)
            {
                if (format == 1)
                {
                    ddlYearList.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }
                else if (format == 2)
                {
                    ddlYearList.Items.Add(new ListItem(i.ToString().Substring(2, 2), i.ToString()));
                }
            }
        }

        /// <summary>
        /// strDate should be like example (1/Mar/2011, 1/March/2011/, 01/03/2011)
        /// using DateTime.TryParse(strDate, out _dtTemp)
        /// </summary>
        /// <param name="strDate"></param>
        /// <param name="dtRetDateTime"></param>
        /// <returns></returns>
        public static bool GetDateTime(string strDate, out DateTime dtRetDateTime)
        {
            bool _retValue = false;
            DateTime _dtTemp = DateTime.MinValue;
            dtRetDateTime = _dtTemp;
            if (DateTime.TryParse(strDate, out _dtTemp))
            {
                dtRetDateTime = _dtTemp;
                _retValue = true;
            }

            return _retValue;
        }
    }
}
